<template>
  <div>
    <div class="head">
      <a @click="$router.push({path: '/MyProject'})" class="return"></a>
      {{$t('MyDividendRecord.v1')}}
    </div>
    <div class="overlay">
      <div class="overlay-content scrolling" style="padding-top:10px;">
        <van-pull-refresh v-model="isLoading" @refresh="onRefresh" pulling-text=" " :loosing-text="$t('MyTeam.v8')"
                          :loading-text="$t('MyTeam.v7')">
          <van-list v-model="loading" :finished="finished" :finished-text="$t('Prize.v3')"
                    :loading-text="$t('MyTeam.v7')" @load="onLoad">
            <div style="background: white;border-bottom: 1px solid #ebedf0;" v-for="(item,index) in list" :key="item.index">
              <div style="padding: 10px;">
                <van-row>
                  <van-col span="12">
                    <span>
                      {{$t('MyDividendRecord.v2')}}
                    </span>
                    <div style="padding-top: 5px;font-size: 13px;color: rgb(125, 126, 128);">
                      {{item.createTime | dateFormat}}
                    </div>
                  </van-col>
                  <van-col span="12" style="text-align: right;">
                    <span>
                      {{$t('MyDividendRecord.v3')}}
                    </span>
                    <div style="padding-top: 5px;font-size: 13px;color: rgb(60, 167, 109);">
                      +{{parseFloat(Number(item.num)).toFixed(5).slice(0,-1)}}
                    </div>
                  </van-col>
                </van-row>
              </div>
            </div>
          </van-list>
        </van-pull-refresh>
      </div>
    </div>
  </div>
</template>

<script>
    import {crowdfunding} from './../../utils/api';
    import { dateFormat } from 'vux';
    export default {
        name: "MyDividendRecord",
        data() {
            return {
                list: [],
                size: 10, // 每页数量
                current: 1,
                total: '', // 总数量
                listLength: '', //当前总数量
                isLoading: false,
                finished: false,
                loading: false,
            };
        },
        methods: {
            getList() {
                crowdfunding.getProjectDetailsMine({
                    projectId: this.$route.query.projectId,
                    type: 2,
                    current: this.current,
                    size: this.size
                }).then(res => {
                    if(res.code == 200) {
                        this.list = res.data.records;
                        this.listLength = res.data.records.length;
                        this.total = res.data.total;
                        if (this.total > this.listLength) {
                            this.size += 10;
                            this.loading = false;
                        } else {
                            // 加载状态结束
                            this.finished = true;
                            this.loading = false;
                        }
                    }
                })
            },
            onRefresh() { // 下拉刷新
                this.getList();
                setTimeout(() => {
                    this.$toast({
                        duration: 800,
                        message: this.$t('Prize.v23')
                    });
                    this.isLoading = false;
                }, 500);
            },
            onLoad() { // 上拉加载
                this.getList();
            }
        },
        filters: {
            dateFormat
        }
    }
</script>

<style lang="less" scoped>
  .overlay {
    background: rgb(245, 245, 245);
    color: black;
  }

  .head {
    background: white;
    color: black;
  }

  .head .return:after {
    border-color: #000;
  }
</style>
